package mains;

import java.util.Collection;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import app.Merchant;
import app.Payment;

public class Main2 {

    private static final String UNIT_NAME = "CashM";
    private static EntityManagerFactory factory;
    
    
    public static void main(String[] args) {
	
	factory = Persistence.createEntityManagerFactory(UNIT_NAME);
	EntityManager em = factory.createEntityManager();
	
	Payment payment = null;
	Merchant merchant = null;
	
	try {
	    payment = em.find(Payment.class, 2);
	    merchant = em.find(Merchant.class, 3);
	}
	finally {
	    em.close();    
	}
	
	if(payment!=null){
	    System.out.println(payment.toString());
	}
	
	if(merchant!=null){
	    System.out.println(merchant.toString());
	    Collection<Payment> payments = merchant.getPayments();
	    for(Payment p: payments){
		System.out.println(p.toString());
	    }
	}
	
    }

}
